<?php
class Renderer
{	
	
	/**
	 * 
	 * @var Smarty
	 */
	public $smarty;
	
	/**
	 * 
	 * @var string
	 */
	public $path;
	
	/**
	 * 
	 * @var string
	 */
	public $templateBaseDir = '';	
	
	/**
	 * 
	 * @var string
	 */
	public $template;

	/**
	 * 
	 * @var string
	 */
	protected $subject;
	/**
	 * 
	 * @var string
	 */
	protected $action;
	/**
	 * 
	 * @var int
	 */
	protected $viewId;
	
	/**
	 * 
	 * @var array()
	 */
	protected $arguments;
		
	
	protected function __construct()
	{

		$this->smarty = new Smarty();
		
		$arguments = explode('?', $_SERVER['REQUEST_URI']);
		$arguments = strtolower($arguments[0]);		
		$arguments = explode('/', $arguments);
		array_shift($arguments);
		$this->arguments = $arguments;
		$this->subject = $arguments[0];
		$this->action = $arguments[1];
		$this->viewId = $arguments[2];
		$this->template = 'default.tpl';
	}
	
	/**
	 * 
	 * @param string $tpl_var
	 * @param mixed $value
	 */
	public function assign($tpl_var, $value)
	{
		$this->smarty->assign($tpl_var, $value);
	}
	
	/**
	 * 
	 * @param string $template
	 */
	public function display($template)
	{
		$this->smarty->display($template);
	}
	
	/**
	 * 
	 * @param string $template
	 * @return string rendered template output
	 */
	public function fetch($template)
	{
		return $this->smarty->fetch($template);
	}

	public function showOutput()
	{			
		$this->display('templates' . $this->templateBaseDir . $this->template);
	}
	
	public function redirect($path = null)
	{
		header('location: '.HOST.$path);
		exit;
	}
	
}